#ifndef _CRT_STDTIME_H_
#define _CRT_STDTIME_H_

#include <crt_core.hpp>

#ifdef __cplusplus
extern "C" {
#endif

#define std_timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
#define std_timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)

#if (TARGET_OS == OS_WIN)

struct timezone {
    int tz_minuteswest;
    int tz_dsttime;
};

int _gettimeofday(struct timeval* tv, struct timezone* tz);

#endif

#if (TARGET_OS != OS_WIN)
unsigned long GetTickCount(void);
#endif

uint64_t _gettimeofday_s(void);
uint64_t _gettimeofday_ms(void);
uint64_t _gettimeofday_us(void);
uint64_t _getclock_ms(void);

struct tm* _localtime_t(const time_t* timep, struct tm* result);
int get_time_t(char* tm, unsigned long len);
long tv_to_msec(const struct timeval* tv);

int timerval_add(struct timeval* utv, struct timeval* ttv, struct timeval* vtv);
int timerval_sub(struct timeval* utv, struct timeval* ttv, struct timeval* vtv);

#define tv_cmp_err   0
#define tv_cmp_suc   1
#define tv_cmp_great 10
#define tv_cmp_less  11

#ifndef TVL_PTR
typedef struct timeval* TVL_PTR;
#endif

int timerval_cmp(struct timeval* utv, struct timeval* ttv);

#ifdef __cplusplus
}
#endif

#endif
